/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Jadwal.java
 *
 * Created on Nov 24, 2011, 12:29:39 PM
 */
package DataMobil;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Piyo
 */
public class Jadwal extends javax.swing.JPanel {

    /** Creates new form Jadwal */
    public Jadwal() {
        initComponents();
        GregorianCalendar gc = new GregorianCalendar();
        tanggalJadwalChooser.setDate(gc.getTime());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        jLabel1 = new javax.swing.JLabel();
        tanggalJadwalChooser = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jadwalTabel = new javax.swing.JTable();
        background = new javax.swing.JLabel();

        jDesktopPane1.setBackground(new java.awt.Color(255, 0, 153));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("TANGGAL");
        jLabel1.setBounds(260, 60, 90, 30);
        jDesktopPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tanggalJadwalChooser.setDateFormatString("dd-MM-yyyy");
        tanggalJadwalChooser.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                tanggalJadwalChooserPropertyChange(evt);
            }
        });
        tanggalJadwalChooser.setBounds(340, 60, 130, 30);
        jDesktopPane1.add(tanggalJadwalChooser, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("JADWAL PEMAKAIAN MOBIL");
        jLabel2.setBounds(230, 10, 370, -1);
        jDesktopPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jScrollPane1.setDoubleBuffered(true);

        jadwalTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "IDMOBIL", "NAMA MOBIL", "ID PENYEWA", "NAMA PENYEWA", "PINJAM", "KEMBALI"
            }
        ));
        jScrollPane1.setViewportView(jadwalTabel);

        jScrollPane1.setBounds(10, 110, 750, 90);
        jDesktopPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        background.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DataMobil/hucomm5jv7-iam-blue-wallpaper.jpg"))); // NOI18N
        background.setBounds(0, 0, 780, 300);
        jDesktopPane1.add(background, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void tanggalJadwalChooserPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_tanggalJadwalChooserPropertyChange
        // TODO add your handling code here:


        try {

            String formatTanggal = "dd-MM-yyyy";
            SimpleDateFormat sdf = new SimpleDateFormat(formatTanggal);
            String tanggal = String.valueOf(sdf.format(tanggalJadwalChooser.getDate()));
//            int bulanChooser = Integer.parseInt(tanggal);
            DataSewa sewaBaru = new DataSewa();
            sewaBaru.setTgl_sewa(tanggal);


            Intermobil mobil = new Intermobil();
            mobil.getJadwal(tanggal);


            List<DataSewa> sewa = mobil.getJadwal(tanggal);
            JadwalTableModel model = new JadwalTableModel(sewa);
            jadwalTabel.setModel(model);

        } catch (SQLException ex) {
            Logger.getLogger(Jadwal.class.getName()).log(Level.SEVERE, null, ex);

        }

    }//GEN-LAST:event_tanggalJadwalChooserPropertyChange
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel background;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jadwalTabel;
    private com.toedter.calendar.JDateChooser tanggalJadwalChooser;
    // End of variables declaration//GEN-END:variables
}
